package com.zoo.buyor.user.controller;


import com.zoo.buyor.common.domain.vo.request.RequestInfo;
import com.zoo.buyor.common.domain.vo.response.ApiResult;
import com.zoo.buyor.interceptor.RequestHolder;
import com.zoo.buyor.user.domain.vo.request.ModifyNameReq;
import com.zoo.buyor.user.domain.vo.response.user.BadgeResp;
import com.zoo.buyor.user.domain.vo.response.user.UserInfoResp;
import com.zoo.buyor.user.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import java.util.List;

/**
 * <p>
 * 用户表 前端控制器
 * </p>
 *
 * @author <a href="https://gitee.com/ArZoo">阿祖</a>
 * @since 2024-01-22
 */
@RestController
@RequestMapping("/capi/user")
@Api(tags = "用户接口")
public class UserController {
    @Autowired
    UserService userService;
    @GetMapping("/userInfo")
    @ApiOperation("获取用户信息")
    public ApiResult<UserInfoResp> getUserInfo(){
        return ApiResult.success(userService.getUserInfo(RequestHolder.get().getUid()));
    }

    @PutMapping("/rename")
    @ApiOperation("修改用户名")
    public ApiResult<Void> getUserInfo(@RequestBody ModifyNameReq modifyNameReq){
        userService.modifyName(RequestHolder.get().getUid(),modifyNameReq);
        return ApiResult.success();
    }

    @GetMapping("/badges")
    @ApiOperation("徽章页面")
    public ApiResult<List<BadgeResp>> badges(){
        return ApiResult.success(userService.badges(RequestHolder.get().getUid()));
    }

}

